package org.jsola.contract.helper;

import org.jsola.common.SafeKit;
import org.jsola.contract.dto.ContractConfigSiteAddDTO;
import org.jsola.contract.dto.ContractConfigSiteUpdateDTO;
import org.jsola.contract.entity.ContractConfigSiteDO;
import org.jsola.contract.query.ContractConfigSiteQuery;
import org.jsola.contract.service.IContractConfigSiteService;
import org.jsola.contract.vo.ContractConfigSiteVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.contract.core.AbstractTest.SITE_ID;



/**
 * 租户电子合同配置
 *
 * @author JanusMix
 */
@Component
public class ContractConfigSiteTestHelper extends BaseTestHelper {
    
    @Autowired
    private IContractConfigSiteService contractConfigSiteService;

    /**
     * 生成add测试数据
     * @return ContractConfigSiteAddDTO
     */
    public ContractConfigSiteAddDTO getContractConfigSiteAddDTO(){
        ContractConfigSiteAddDTO contractConfigSiteAddDTO = new ContractConfigSiteAddDTO();
        contractConfigSiteAddDTO.setEnable(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        contractConfigSiteAddDTO.setType(SafeKit.getInteger(getRandomValue("int",11)));
        contractConfigSiteAddDTO.setTotalCount(SafeKit.getInteger(getRandomValue("int",11)));
        contractConfigSiteAddDTO.setQuotaRemain(SafeKit.getInteger(getRandomValue("int",11)));
        contractConfigSiteAddDTO.setEnableCheckFace(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        contractConfigSiteAddDTO.setEnableCheckSms(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return contractConfigSiteAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ContractConfigSiteUpdateDTO
     */
    public ContractConfigSiteUpdateDTO getContractConfigSiteUpdateDTO(ContractConfigSiteVO contractConfigSiteVO){
        return contractConfigSiteService.selectDOById(contractConfigSiteVO.getId(), SITE_ID).to(ContractConfigSiteUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ContractConfigSiteQuery
     */
    public ContractConfigSiteQuery getContractConfigSiteQuery() {
        ContractConfigSiteQuery contractConfigSiteQuery = new ContractConfigSiteQuery();
        List<ContractConfigSiteDO> contractConfigSiteDOList = contractConfigSiteService.list(new ContractConfigSiteDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(contractConfigSiteDOList)) {
            ContractConfigSiteDO contractConfigSiteDO = contractConfigSiteDOList.get(0);
            contractConfigSiteQuery = contractConfigSiteDO.to(ContractConfigSiteQuery.class);
        }
        return contractConfigSiteQuery;
    }

    /**
     * 保存示例
     * @return ContractConfigSiteVO
     */
    public ContractConfigSiteVO saveContractConfigSiteExample(){
        ContractConfigSiteAddDTO addDTO = this.getContractConfigSiteAddDTO();
        ContractConfigSiteVO contractConfigSiteVO = contractConfigSiteService.save(addDTO,buildTokenUser());
        return contractConfigSiteVO;
    }


}

